//

import UIKit
import SDWebImage
//原创微博视图
class CZStatusOriginalView: UIView {
    
    
    //持有对应显示数据的ViewModel
    var statusViewModle: CZStatusViewModel? {
        didSet {
            //判断url是否为nil
            if let imageUrl = statusViewModle?.status?.user?.profile_image_url {
                
                headImageView.sd_setImageWithURL(NSURL(string: imageUrl), placeholderImage:UIImage(named: "avatar_default_big"))
            }
            nameLabel.text = statusViewModle?.status?.user?.screen_name
           
            timeLabel.text = "XX"
            sourceLabel.text = "XX XXX"
            
            //设置微博内容
            contextLabel.text = statusViewModle?.status?.text
        }
    }

    //头像
    private lazy var headImageView: UIImageView = UIImageView(image: (UIImage(named: "avatar_default_big")))
    //认证类型等级图片
    private lazy var renZhengTypeImageView: UIImageView = UIImageView(image: (UIImage(named: "avatar_vip")))
    
    //昵称
    private lazy var nameLabel: UILabel = UILabel(textColor: UIColor.orangeColor(), font: 15)
    
    //会员等级
    private lazy var dengJiIamgeView: UIImageView = UIImageView(image: (UIImage(named: "common_icon_membership")))
    //时间
    private lazy var timeLabel: UILabel = UILabel(textColor: UIColor.orangeColor(), font: 12)
    //来源
    private lazy var sourceLabel: UILabel = UILabel(textColor: UIColor.lightGrayColor(), font: 12)
    
    //微博内容
    private lazy var contextLabel: UILabel = {
       let messageLabel = UILabel(textColor: UIColor.darkGrayColor(), font: 15)
        //分行
        messageLabel.numberOfLines = 0
        
        return messageLabel
        
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        //调用方法
        setUpUiSubView()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置空间约束
    private func setUpUiSubView() {
     
        //添加空间
        addSubview(headImageView)
        addSubview(renZhengTypeImageView)
        addSubview(nameLabel)
        addSubview(dengJiIamgeView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(contextLabel)
        
        //添加约束
        headImageView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self).offset(HomeCellMargin)
            make.top.equalTo(self).offset(HomeCellMargin)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        renZhengTypeImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImageView.snp_trailing)
            make.centerY.equalTo(headImageView.snp_bottom)
        }
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headImageView)
            make.leading.equalTo(headImageView.snp_trailing).offset(HomeCellMargin)
            
        }
        dengJiIamgeView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(nameLabel.snp_trailing).offset(HomeCellMargin)
            make.top.equalTo(nameLabel)
        }
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(headImageView)
            make.leading.equalTo(headImageView.snp_trailing).offset(HomeCellMargin)
        }
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(timeLabel.snp_trailing).offset(HomeCellMargin)
            make.bottom.equalTo(timeLabel)
        }
        contextLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headImageView.snp_bottom).offset(HomeCellMargin)
            make.leading.equalTo(headImageView)
            make.trailing.equalTo(self).offset(-HomeCellMargin)
        }
        
        //原创微博底部约束
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(contextLabel)
        }      
    }
}








